home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util4 / chunker.lha / Chunker / source / chunker.c < prev    next >
C/C++ Source or Header  |  1995-11-10  |  2KB  |  79 lines

  1. /*************************************************************************
  2.  *
  3.  * Chunker
  4.  *
  5.  * Copyright ©1995 Lee Kindness and Evan Tuer
  6.  * cs2lk@scms.rgu.ac.uk
  7.  *
  8.  * chunker.c
  9.  */
  10.  
  11. #include "chunker.h"
  12.  
  13.  
  14. /*************************************************************************
  15.  * main() - DaDDDaaah!
  16.  */
  17.  
  18. int main(int argc, char **argv)
  19. {
  20.     long ret = 10;
  21.     /* init */
  22.     if( InitSystem() )
  23.     {
  24.         struct Args *args;
  25.         
  26.         if( args = GetChunkerArgs(argc, argv) )
  27.         {
  28.             FILEt source;
  29.             
  30.             /* Open input file */
  31.             if( source = mfopen(args->arg_Filename, FILEOPEN_READ) )
  32.             {
  33.                 char *destname;
  34.                 long num = 0;
  35.                 FILEt dest = NULL;
  36.  
  37.                 if( (destname = BuildFName(args->arg_Basename, &num)) &&
  38.                     (dest = mfopen(destname, FILEOPEN_WRITE)) )
  39.                 {
  40.                     register long n = 0;
  41.                     register int c;
  42.                     
  43.                     mprintf("%s\n", destname);
  44.                     
  45.                     for( c = mfgetc(source);
  46.                          c != EOF;
  47.                          c = mfgetc(source), ++n)
  48.                     {
  49.                         if( n == args->arg_Size )
  50.                         {
  51.                             FreeFName(destname);
  52.                             mfclose(dest);
  53.                             destname = BuildFName(args->arg_Basename, &num);
  54.                             mprintf("%s\n", destname);
  55.                             dest = mfopen(destname, FILEOPEN_WRITE);
  56.                             n = 0;
  57.                         }
  58.                         mfputc(c, dest);
  59.                     }
  60.                 }
  61.                 FreeFName(destname);
  62.                 mfclose(dest);
  63.                 mfclose(source);
  64.                 
  65.                 ret = 0;
  66.             } else
  67.                 mprintf("Can't open %s\n", args->arg_Filename);
  68.             
  69.             FreeChunkerArgs(args);
  70.             
  71.         } /* else arg fail */
  72.         
  73.         FreeSystem();    
  74.     } else
  75.         mprintf("Usage:\n chunker <file> <basename> <size>\n");
  76.     
  77.     return( ret );
  78. }
  79.